package rule

import "regexp"

func init() {
	Register(&chsAlphaNumRule{Regexp: regexp.MustCompile(`^[\p{Han}a-zA-Z0-9]+$`)})
}

type chsAlphaNumRule struct {
	*regexp.Regexp
}

func (c *chsAlphaNumRule) Name() string {
	return "chsAlphaNum"
}

func (c *chsAlphaNumRule) Check(in *RuleInput) (err error) {
	if v, ok := in.Value.(string); ok && v != "" && c.FindStringIndex(v) != nil {
		return
	}
	return in.Error()
}
